home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CTBChannel.h
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <22> 12/12/94 TMH added IsOpen()
- <21> 11/17/94 TMH added Disconnect
- <20> 11/8/94 TMH changes to support async P3 thread
- <19> 11/2/94 JHB Adding support for Sending eWorld Mail
- <18> 11/2/94 TMH added no carrier detect stuff, and WriteBytes
- <17> 10/28/94 TMH added FlushRead,FlushWrite and some other stuff
- <16> 10/28/94 TMH made async and X25 work better
- <15> 10/25/94 TMH made open,close, read & write asynchronous
- <13> 10/21/94 TMH created TModemChannel and TX25Channel
- <11> 10/20/94 TMH added IsToolMacPad() etc
- <10> 10/18/94 TMH pass external slot to ICTBChannel
- <10> 10/18/94 TMH pass external slot to ICTBChannel
-
- To Do:
- */
-
-
- #ifndef _CTBCHANNEL_
- #define _CTBCHANNEL_
-
-
- class TWakeupThread;
- class TCTBIdleThread;
-
- #ifndef __ExternalSlot__
- #include "ExternalSlot.h"
- #endif
-
- #ifndef __PMSAMResources__
- #include "PMSAMResources.h"
- #endif
-
- #ifndef __CONNECTIONS__
- #include <Connections.h>
- #endif
-
- #ifndef __LogErrors__
- #include "LogErrors.h"
- #endif
-
- #ifndef __TThread__
- #include "TThread.h"
- #endif
-
-
- #define kDontWaitForPending true
- #define kWaitForPending false
-
- #define kDoAsync true
- #define kDoSync false
-
- // defines for the various connection networks
-
- #define NO_NETWORK 0
- #define SPRINTNET 1
- #define MCI 2
-
-
- inline Boolean IsCTBError(CMErr cmErr) { return (cmErr > 0) && (cmErr <= cmUnknownError); };
-
- //-----------------------
- // T C T B C h a n n e l
- //---------------------------
-
- class TCTBChannel {
-
- public:
- TCTBChannel( );
- ~TCTBChannel( );
-
- void ICTBChannel(short toolParamResID, StringPtr toolName, TExternalSlot* slot );
- void SetCTBParametersFromResource(short resID);
-
-
- //--------------------
- // Reading & Writing
- //--------------------
-
-
- CMErr Read ( char *theBuffer, long bytesToRead, long timeOut);
- CMErr Write ( char *theBuffer, long bytesToWrite, long timeOut);
-
-
- // these ones FAIL
- char ReadByte();
- void ReadBytes(char *theBuffer, long bytesToRead );
-
-
- void Waitfor( short time);
- char WaitFor(char waitFor);
- char WaitForOneOf(char *searchString); // wait 'oneof' found or timeout fail
-
- void WaitForString (char* searchString); // wait till success or timeout fail
- void SendString(char* sendString); // wait till success or timeout fail
-
-
- void WriteBytes(void* data, long dataLen);
-
- //-------
- // Misc.
- //-------
-
- void IdleChannel();
- void FlushRead( );
- void FlushWrite( );
-
-
-
- //--------------
- // Accessors
- //--------------
-
-
- long OpenTimeout() { return fOpenTimeout; };
- long CloseTimeout() { return fCloseTimeout; };
- long ReadTimeout() { return fReadTimeout; };
- long WriteTimeout() { return fWriteTimeout; };
-
-
- CMStatFlags GetCMStatus();
- Boolean IsOpen();
-
- Boolean IsIOPending();
- Boolean IsOpenPending();
- Boolean IsReadPending();
- Boolean IsWritePending();
- long DataAvail();
- CMErr KillAllIO();
- CMErr Abort();
-
-
- //-----------------
- // Connecting
- //-----------------
-
- OSErr Connect(Ptr configStr);
- virtual void MakeConnection() = 0;
- void Disconnect();
-
- CMErr Open();
- CMErr Close();
-
- virtual void NetworkLogin();
-
-
- protected:
-
- static pascal void __CTBCompletorProc(ConnHandle theConnectionHandle);
-
- private:
- void InitializeCTB();
-
- protected:
-
-
- CommState fCommState;
- ConnHandle fConnH; // the Connection Handle for the channel
-
-
- TWakeupThread* fWakeupThread; // for async I/O
- TExternalSlot* fExternalSlot;
-
-
- // CTB Parameters
-
-
- long fReadTimeout;
- long fWriteTimeout;
- long fOpenTimeout;
- long fCloseTimeout;
-
-
- Boolean fOpenASync;
- Boolean fCloseASync;
- Boolean fReadASync;
- Boolean fWriteASync;
-
- long fConfigBufSize;
-
- long fBaudRate; // baud rate for modems, 0 if not using modem tool (like for X.25)
-
- private:
-
- ConnEnvironRec fConnEnvironRec; // the ConnEvironRec for the channel (connection environment record)
- // has the CMChannel, CMFlags, as well as version, baudrate, databits and flowControl settings
-
- CMBufferSizes fBufferSizesArray; // holds the sizes of the various CTB buffers for each CTB channel
-
- TCTBIdleThread* fCTBIdleThread;
- };
-
-
-
-
- //---------------------------
- // T M o d e m C h a n n e l
- //---------------------------
-
- class TModemChannel : public TCTBChannel {
- public:
- TModemChannel();
- void IModemChannel(StringPtr toolName, TExternalSlot* exSlot);
-
- virtual void NetworkLogin();
- virtual void MakeConnection();
-
- void ClearNoCarrierDetected() { fNoCarrierDetected = false; };
- private:
- void SprintNetLogin ();
- static pascal void NoCarrierDetectProc(ConnHandle hConn,Ptr matchPtr,long refNum);
-
- private:
- short fAccessNetwork;
-
- long fNoCarrierDetectRefNum; // value returned from CMAddSearch
- Boolean fNoCarrierDetected; // set by NoCarrierDetectProc
-
- };
-
-
- //---------------------------
- // T X 2 5 C h a n n e l
- //---------------------------
-
- class TX25Channel : public TCTBChannel {
- public:
- TX25Channel();
- void IX25Channel(StringPtr toolName, TExternalSlot* exSlot);
-
- virtual void NetworkLogin();
- virtual void MakeConnection();
-
- };
-
-
- //-------------------------------------
- // T C T B I d l e T h r e a d
- //--------------------------------------
-
- #define kCTBIdleThreadStackSize 16000
- class TCTBIdleThread : public TCooperativeThread {
-
- public:
- TCTBIdleThread();
- void ICTBIdleThread(TCTBChannel* ctbChannel);
-
- virtual void* ThreadMain();
-
- private:
- TCTBChannel* fCTBChannel;
- };
-
-
-
- #endif
-
-
-